package com.bill99.golden.inf.sso.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Statistics {
	private static Log log = LogFactory.getLog(Statistics.class);
	private static long createMinTime = Integer.MAX_VALUE;
	private static long createMaxTime = 0;
	private static long createTotalTime = 0;
	private static long createCnt = 0;
	private static Object createLock = new Object();

	private static long validateMinTime = Integer.MAX_VALUE;
	private static long validateMaxTime = 0;
	private static long validateTotalTime = 0;
	private static long validateCnt = 0;
	private static Object validateLock = new Object();

	private static long destroyMinTime = Integer.MAX_VALUE;
	private static long destroyMaxTime = 0;
	private static long destroyTotalTime = 0;
	private static long destroyCnt = 0;
	private static Object destroyLock = new Object();

	public static void addCreateLog(long time) {
		synchronized (createLock) {
			createCnt++;
			createTotalTime += time;
			if (time < createMinTime)
				createMinTime = time;
			if (time > createMaxTime)
				createMaxTime = time;
			log.debug("time=" + time + " createCnt=" + createCnt
					+ " createTotalTime=" + createTotalTime + " createMinTime="
					+ createMinTime + " createMaxTime=" + createMaxTime);
		}
	}

	public static void addValidateLog(long time) {
		synchronized (validateLock) {
			validateCnt++;
			validateTotalTime += time;
			if (time < validateMinTime)
				validateMinTime = time;
			if (time > validateMaxTime)
				validateMaxTime = time;
			log.debug("time=" + time + " validateCnt=" + validateCnt
					+ " validateTotalTime=" + validateTotalTime
					+ " validateMinTime=" + validateMinTime
					+ " validateMaxTime=" + validateMaxTime);
		}
	}

	public static void addDestroyLog(long time) {
		synchronized (destroyLock) {
			destroyCnt++;
			destroyTotalTime += time;
			if (time < destroyMinTime)
				destroyMinTime = time;
			if (time > destroyMaxTime)
				destroyMaxTime = time;
			log.debug("time=" + time + " destroyCnt=" + destroyCnt
					+ " destroyTotalTime=" + destroyTotalTime
					+ " destroyMinTime=" + destroyMinTime + " destroyMaxTime="
					+ destroyMaxTime);
		}
	}

	public static long getCreateMinTime() {
		return createMinTime;
	}

	public static long getCreateMaxTime() {
		return createMaxTime;
	}

	public static long getCreateTotalTime() {
		return createTotalTime;
	}

	public static long getCreateCnt() {
		return createCnt;
	}

	public static long getValidateMinTime() {
		return validateMinTime;
	}

	public static long getValidateMaxTime() {
		return validateMaxTime;
	}

	public static long getValidateTotalTime() {
		return validateTotalTime;
	}

	public static long getValidateCnt() {
		return validateCnt;
	}

	public static long getDestroyMinTime() {
		return destroyMinTime;
	}

	public static long getDestroyMaxTime() {
		return destroyMaxTime;
	}

	public static long getDestroyTotalTime() {
		return destroyTotalTime;
	}

	public static long getDestroyCnt() {
		return destroyCnt;
	}
}
